/*
* $Id: uart.c,v 1.3 2007/11/21 06:45:33 sunny Exp $
*/
/*******************************************************************************

       UBEC (Uniband Electronic Corp.)

       Project: U-NET01, Ubiquitous network platform

       File: uart.c

       Version: 0.2.3

       Usage: Uart functions

       Platform: U-NET01 DK with Keil 8051 C compiler

       Reference:

               Silicon Laboratories: C8051F124, C8051F340

               UBEC: UZ2400, UZ2410

       Note :

               Copyright (C) 2007 Uniband Electronic Corporation, All rights reserved

********************************************************************************/
#include "unet.h"

#ifdef CONSOLE
/********************************************************************************
********************************************************************************/
void InitUART()
{
	InitUartVars();

#if defined(M430F1611)
	/* RS232 */
	P3SEL |= 0xC0;			// P3.6,7 = USART1 option select

	ME2 |= (UTXE1 | URXE1);		// Enable USART1 TXD/RXD

	UCTL1 |= CHAR;			// 8-bit character
	UTCTL1 |= SSEL1;		// UCLK = SMCLK
    #if 0
	UBR01 = 0x11;			// 2MHz/115200 = 17.36
	UBR11 = 0;			//
	UMCTL1 = 0x4A;			// modulation control
    #else
	UBR01 = 0x2A;			// 4.9MHz/115200 = 42.53
	UBR11 = 0;			//
	UMCTL1 = 0x4A;			// modulation control
    #endif
	UCTL1 &= ~SWRST;		// Initialize USART state machine

	IE2 |= (UTXIE1 | URXIE1);	// Enable USART1 TX/RX interrupt
#else
	#error "Unknown CPU type."
#endif
}

/********************************************************************************
********************************************************************************/
#pragma message (__LOC__ "uart_putc() is called by interrupt service routine and main program.")
void uart_putc(UINT8 c)		// called by putchar() and uart_tx_isr()
{
	CONSOLE_putc(c);
}

/********************************************************************************
********************************************************************************/
#pragma message (__LOC__ "uart_getc() is called by interrupt service routine.")
UINT8 uart_getc(void)		// called by uart_rx_isr()
{
	return CONSOLE_getc();
}

#endif // #ifdef CONSOLE
